package alf.common.view.activity;

import alf.mapping.view.activity.R;
import alf.mapping.view.visuals.EditorEngine;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;

public abstract class AbstractTextSelectionActivity extends Activity {

	int selected = -1;
	String[] names= null;
	@Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.text_selection);

		ListView lista = (ListView) findViewById(R.id.names_list);
		names = loadData();
		lista.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_spinner_dropdown_item, names));
		lista.setOnItemClickListener(new ListView.OnItemClickListener(){
				public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
					selected = (position);
				}
			});
	}
	
	protected abstract String[] loadData();

	public void onOk(View v) {
		Intent i = getIntent();
		i.putExtra(Intent.EXTRA_RETURN_RESULT,selected);
		i.putExtra(Intent.EXTRA_TEXT,names[selected]);
		setResult(RESULT_OK, i);
		finish();
	}

	public void onCancel(View v) {
		setResult(Activity.RESULT_CANCELED);
		finish();
	}

}
